import {
  addDriveParaCal,
  afterExportUpdate,
  calDriveParasCal,
  delDriveParaCal,
  delDriveParasCal,
  driveParaCalExcelExport,
  driveParaCalExcelExportPMVer,
  getDriveParaCalByPage,
  getDriveParaCalTwoByPage,
  matchDriveParasCal,
  updateDriveParaCal,
  uploadDriveParaCalExcel,
} from '@/services/drivepara/driveparacal';
import { CalculatorOutlined, CarryOutOutlined, CloudDownloadOutlined, CloudUploadOutlined, DeleteOutlined, PlusOutlined } from '@ant-design/icons';
import { ModalForm, PageHeaderWrapper, ProCard, ProCardTabsProps, ProColumns, ProForm, ProFormDependency, ProFormGroup, ProFormInstance, ProFormSelect, ProFormText, ProFormTextArea, ProTable } from '@ant-design/pro-components';
import ProList from '@ant-design/pro-list';
import { Button, Form, Modal, Radio, RadioChangeEvent, Space, Tag, message } from 'antd';
import { ReactText, useEffect, useRef, useState } from 'react';
import DriveParaLibCommon from './driveParaLibCommon';
import UploadFileSave from '@/components/UploadExcelSave';
import Tree, { DataNode } from 'antd/lib/tree';
import styles from './style.less';
import DriveParaCalcCommon from './driveParaCalcCommon';
import DriveParaCalcSubtitle from '@/components/DriveParaCalc/DriveParaCalcSubtitle';
import DriveParaCalcDescription from '@/components/DriveParaCalc/DriveParaCalcDescription';
import DriveParaCalcEdit from './driveParaCalcEdit';
import type { FormLayout } from 'antd/es/form/Form';
import DebounceSelect from '@/components/DebounceSelect';
import { calcDeviceList } from '@/services/device/deviceInfo';
import { useLocation } from 'umi';
import DriveParaDescription from '@/components/DriveParaCalc/DriveParaDescription';
import DriveParaSubtitle from '@/components/DriveParaCalc/DriveParaSubtitle';
import G120TreeData from '@/components/Columns/G120TreeData';
import { addG120DeviceInfo, delG120DeviceInfo, updateG120DeviceInfo } from '@/services/drivepara/driveParaLibG120Eng';
import { getDeviceInfoLibByPage } from '@/services/drivepara/deviceInfoLibEng';
import { addDriveParaCalG120, calDriveParasCalG120, delDriveParaCalG120, delDriveParasCalG120, driveParaCalG120ExcelExport, getDriveParaCalG120ByPage, updateDriveParaCalG120, uploadDriveParasCalG120Excel } from '@/services/drivepara/driveParaCalG120';
import G120DriveParaSubtitle from '@/components/DriveParaCalc/G120DriveParaSubtitle';
import G120LibEngShaftCommon from '@/components/DriveParaCalc/G120LibEngShaftCommon';
import G120CalcUploadColumns from '@/components/Columns/G120Columns';
// import type { UploadFile, UploadProps } from 'antd/es/upload/interface';
const LAYOUT_TYPE_HORIZONTAL = 'horizontal';
const DriveParaCalc: React.FC<{}> = () => {
  const [expandedRowKeys, setExpandedRowKeys] = useState<readonly ReactText[]>([]);
  const [dataSource, setDataSource] = useState<any[]>([]);
  const [dataSourceTwo, setDataSourceTwo] = useState<any[]>([]);
  const [libCommVis, setLibCommVis] = useState(false);
  const [editVis, setEditVis] = useState(false);
  const [exportVis, setExportVis] = useState(false);
  const [exportPMVis, setExportPMVis] = useState(false);
  const [formLayoutType, setFormLayoutType] = useState<FormLayout>(LAYOUT_TYPE_HORIZONTAL);
  const [grid, setGrid] = useState(true);
  const [form] = Form.useForm();
  const [values, setValues] = useState({});
  const [axiosCreate, setAxiosCreate] = useState<Boolean>(false);
  const driveRef = useRef(null);
  const uploadRef = useRef(null);
  const [uploadVis, setUploadVis] = useState(false);
  const [selectedRowKeys, setSelectedRowKeys] = useState<ReactText[]>([]);
  const [selectedKeys, setSelectedKeys] = useState([]);
  const formData = new FormData();
  // const [fileList, setFileList] = useState<UploadFile[]>([]);
  const rowSelection = {
    selectedRowKeys,
    onChange: (keys: ReactText[]) => {
      setSelectedRowKeys(keys);
      console.log(keys, "---keys---");
    },
  };
  const actionRef = useRef<ActionType>();

  const [expandedKeys, setExpandedKeys] = useState<React.Key[]>(['lib3']);
  const [checkedKeys, setCheckedKeys] = useState<React.Key[]>(['lib0', 'lib4-0', 'lib4-1', 'lib4-2', 'lib4-3', 'lib4-4',
  'libG120-0', 'libG120-4-2', 'libG120-5-0-0', 'libG120-5-0-5', 'libG120-5-1-1', 'libG120-5-1-6']);
  
  const location = useLocation();
  const [autoExpandParent, setAutoExpandParent] = useState<boolean>(true);

  const [kpDefaultChecked, setKpDefaultChecked] = useState(false);

  const exportFormRef = useRef<ProFormInstance>();
  const [deviceDisabled, setDeviceDisabled] = useState(false);

  const [radioValue, setRadioValue] = useState(1);
  const [tab, setTab] = useState('tab1-1');
  const [tabPosition, setTabPosition] = useState<ProCardTabsProps['tabPosition']>('top');
  const [deviceId, setDeviceId] = useState(null);
  const [deviceName, setDeviceName] = useState(null);
  const [tab2Disable, setTab2Disable] = useState(true);

  const [uploadVisG120, setUploadVisG120] = useState(false);
  const [deviceVisG120, setDeviceVisG120] = useState(false);
  const [deviceG120Values, setDeviceG120Values] = useState({});
  const [g120DataSource, setG120DataSource] = useState<any[]>([]);
  const [g120CommVis, setG120CommVis] = useState(false);
  const [g120Values, setG120Values] = useState({});
  const [g120Create, setG120Create] = useState<Boolean>(false);

  const tableActionRef = useRef<ActionType>();
  const tableRef = useRef(null);
  const formRef = useRef<ProFormInstance>();

  const onRadioChange = (e: RadioChangeEvent) => {
    console.log('radio checked', e.target.value);
    setRadioValue(e.target.value);
    actionRef.current?.reload();
  };


  const columns: ProColumns[] = [
    {
      title: '序号',
      dataIndex: 'index',
      valueType: 'index',
      width: 40,
      align: 'center',
    },
    {
      title: '轴名称',
      search: false,
      dataIndex: 'shaftName',
      width: 60,
      align: 'center',
    },
    {
      title: '硬件标识符',
      search: false,
      dataIndex: 'hardwareIdentifier',
      width: 60,
      align: 'center',
    },
    {
      title: '驱动类型',
      width: 60,
      search: false,
      align: 'center',
      key: 'driveType',
      dataIndex: 'driveType',
      valueType: 'select',
      valueEnum: {
        1: { text: 'V90', status: 'Default' },
        2: {
          text: 'S210',
          status: 'success',
        },
      },
    },
    {
      title: '电机订货号',
      search: false,
      align: 'center',
      dataIndex: 'motorOrderNum',
      width: 100,
    },
    // {
    //   title: '电机ID',
    //   search: false,
    //   align: 'center',
    //   dataIndex: 'motorId',
    //   width: 60,
    // },
    // {
    //   title: '编码器',
    //   search: false,
    //   align: 'center',
    //   dataIndex: 'ecoderType',
    //   valueType: 'select',
    //   valueEnum: {
    //     0: { text: '单圈绝对值编码器' },
    //     1: { text: '多圈绝对值编码器' },
    //     2: { text: '增量编码器' },
    //   },
    //   width: 60,
    // },
    // {
    //   title: '抱闸',
    //   search: false,
    //   align: 'center',
    //   dataIndex: 'brake',
    //   valueType: 'select',
    //   valueEnum: {
    //     0: { text: '不带抱闸' },
    //     1: { text: '带抱闸' },
    //   },
    //   width: 60,
    // },
    // {
    //   title: '额定电压',
    //   search: false,
    //   align: 'center',
    //   dataIndex: 'ratedVoltage',
    //   width: 60,
    // },
    // {
    //   title: '额定电流',
    //   search: false,
    //   align: 'center',
    //   dataIndex: 'ratedCurrent',
    //   width: 60,
    // },
    // {
    //   title: '额定功率',
    //   search: false,
    //   align: 'center',
    //   dataIndex: 'ratedPower',
    //   width: 60,
    // },
    // {
    //   title: '额定速度',
    //   search: false,
    //   align: 'center',
    //   dataIndex: 'ratedSpeed',
    //   width: 60,
    // },
    // {
    //   title: '额定转矩',
    //   search: false,
    //   align: 'center',
    //   dataIndex: 'ratedTorque',
    //   width: 60,
    // },
    // {
    //   title: '电机惯量',
    //   search: false,
    //   align: 'center',
    //   dataIndex: 'motorInertia',
    //   width: 60,
    // },
    {
      title: '负载类型',
      align: 'center',
      dataIndex: 'loadType',
      valueType: 'select',
      valueEnum: {
        1: { text: '水平' },
        2: { text: '旋转' },
        3: { text: '垂直' },
        4: { text: '斜坡' },
        5: { text: '其它' },
      },
      width: 60,
    },
    {
      title: '机械结构',
      search: false,
      align: 'center',
      dataIndex: 'mechanicalStructure',
      valueType: 'select',
      valueEnum: {
        1: { text: '丝杠' },
        2: { text: '齿轮齿条' },
        3: { text: '皮带轮' },
        4: { text: '圆盘' },
        5: { text: '辊式带' },
        6: { text: '链条' },
        7: { text: '其它' },
      },
      width: 60,
    },
    {
      title: '控制模式',
      search: false,
      align: 'center',
      dataIndex: 'controlMode',
      valueType: 'select',
      valueEnum: (row) => {
        return {
          1: { text: 'TO' },
          2: { text: 'Epos' },
          3: { text: 'Speed' },
        };
      },
      width: 60,
    },
    {
      title: '通讯报文',
      search: false,
      align: 'center',
      dataIndex: 'commTelegram',
      valueType: 'select',
      valueEnum: {
        105: { text: '105' },
        111: { text: '111' },
        102: { text: '102' },
        3: { text: '3' },
        1: { text: '1' },
      },
      width: 60,
    },
    {
      title: '附加报文',
      search: false,
      align: 'center',
      dataIndex: 'additionalTelegram',
      valueType: 'select',
      valueEnum: {
        999: { text: 'None' },
        750: { text: '750' },
      },
      width: 60,
    },
    {
      title: '电机转速 (EPOS) (rpm)',
      search: false,
      align: 'center',
      dataIndex: 'gearRationMotor',
      width: 60,
    },
    {
      title: '负载转速 (EPOS) (rpm)',
      search: false,
      align: 'center',
      dataIndex: 'gearRationLoad',
      width: 60,
    },
    {
      title: '负载一圈距离(mm或o) (EPOS)',
      search: false,
      align: 'center',
      dataIndex: 'loadOneTurnDistance',
      width: 100,
    },
    {
      title: '设备最大速度Vmax(V90 EPOS)（m/s）', //表头显示的名称
      search: false,
      align: 'center',
      width: 60,
      dataIndex: 'vmaxEpos',
    },

    {
      title: '0-Vmax时间(V90 EPOS) （s）', //表头显示的名称
      search: false,
      align: 'center',
      width: 80,
      dataIndex: 'increaseTimeEpos',
      valueType: 'select',
      valueEnum: {
        1: { text: '<0.05' },
        2: { text: '0.05-0.09' },
        3: { text: '0.1-0.2' },
        4: { text: '0.25-0.4' },
        5: { text: '0.45-0.9' },
        6: { text: '1.0-2.0' },
        7: { text: '2.0-4.0' },
        8: { text: '>4.0' },
      },
    },
    {
      title: 'Vmax-0时间(V90 EPOS) （s）', //表头显示的名称
      search: false,
      align: 'center',
      width: 80,
      dataIndex: 'decreaseTimeEpos', // 列数据在数据项中对应的路径，支持通过数组查询嵌套路径
      valueType: 'select',
      valueEnum: {
        1: { text: '<0.05' },
        2: { text: '0.05-0.09' },
        3: { text: '0.1-0.2' },
        4: { text: '0.25-0.4' },
        5: { text: '0.45-0.9' },
        6: { text: '1.0-2.0' },
        7: { text: '2.0-4.0' },
        8: { text: '>4.0' },
      },
    },
  ];

  const treeData: DataNode[] = [
    {
      title: '轴名称',
      key: 'lib0',
    },
    {
      title: '驱动配置',
      key: 'lib4',
      children: [
        {
          title: '负载类型',
          key: 'lib4-0'
        },
        {
          title: '机械结构',
          key: 'lib4-1'
        },
        {
          title: '控制报文 P922',
          key: 'lib4-2'
        },
        {
          title: '附加报文 P8864',
          key: 'lib4-3'
        },
        {
          title: '控制模式',
          key: 'lib4-4'
        },
        {
          title: '电机旋转方向',
          key: 'lib4-5'
        },
        {
          title: '电机最大转速 P1082',
          key: 'lib4-6'
        },
        {
          title: '参考转速 P2000',
          key: 'lib4-7'
        },
        {
          title: '参考电流 P2002',
          key: 'lib4-8'
        },
        {
          title: '参考转矩 P2003',
          key: 'lib4-9'
        },
        {
          title: '数字输入',
          key: 'lib4-10',
          children: [
            {
              title: 'DI1 P29301',
              key: 'lib4-10-0'
            },
            {
              title: 'DI2 P29302',
              key: 'lib4-10-1'
            },
            {
              title: 'DI3 P29303',
              key: 'lib4-10-2'
            },
            {
              title: 'DI4 P29304',
              key: 'lib4-10-3'
            },
          ],
        },
        {
          title: '数字输出',
          key: 'lib4-11',
          children: [
            {
              title: 'DO1 P29330',
              key: 'lib4-11-0'
            },
            {
              title: 'DO2 P29331',
              key: 'lib4-11-1'
            },
          ],
        },
        {
          title: '转矩限幅值',
          key: 'lib4-12',
          children: [
            {
              title: '转矩限幅上限 P29050[0]',
              key: 'lib4-12-0'
            },
            {
              title: '转矩限幅下限 P29051[0]',
              key: 'lib4-12-1'
            },
          ],
        },
        {
          title: '抱闸配置',
          key: 'lib4-13',
          children: [
            {
              title: '抱闸配置 P1215',
              key: 'lib4-13-0'
            },
            {
              title: '抱闸打开时间 P1216',
              key: 'lib4-13-1'
            },
            {
              title: '抱闸闭合时间 P1217',
              key: 'lib4-13-2'
            },
          ],
        },
      ],
    },
    {
      title: '工艺参数',
      key: 'lib5',
      children: [
        {
          title: '动态系数',
          key: 'lib5-00',
        },
        {
          title: 'EPOS',
          key: 'lib5-0',
          children: [
            {
              title: '负载转速 P29248',
              key: 'lib5-0-0',
            },
            {
              title: '电机转速 P29249',
              key: 'lib5-0-1',
            },
            {
              title: '10mm对应的LU',
              key: 'lib5-0-2',
            },
            {
              title: '每转LU P29247',
              key: 'lib5-0-3',
            },
            {
              title: '位置环增益 P29110',
              key: 'lib5-0-4',
            },
            {
              title: '位置环滤波 P2533',
              key: 'lib5-0-5',
            },
            {
              title: '速度前馈系数 P29111',
              key: 'lib5-0-6',
            },
            {
              title: 'EPOS 最大速度 P2571',
              key: 'lib5-0-7',
            },
            {
              title: 'EPOS 最大加速度 P2572',
              key: 'lib5-0-8',
            },
            {
              title: 'EPOS 最大减速度 P2573',
              key: 'lib5-0-9',
            },
            {
              title: 'EPOS 急动限制 P2574',
              key: 'lib5-0-10',
            },
            {
              title: 'EPOS 急动限制激活 P2575',
              key: 'lib5-0-11',
            },
            {
              title: '推力前馈LR质量/推力前馈质量 P2567',
              key: 'lib5-0-12'
            },
            {
              title: '回零参考点逼近速度 P2605',
              key: 'lib5-0-13'
            },
            {
              title: '回零参考点搜索速度 P2608',
              key: 'lib5-0-14'
            },
            {
              title: '模态轴激活 P29245',
              key: 'lib5-0-15'
            },
            {
              title: '模数补偿范围 P29246',
              key: 'lib5-0-16'
            },
            {
              title: 'JOG1速度 P2585',
              key: 'lib5-0-17'
            },
            {
              title: 'JOG2速度 P2586',
              key: 'lib5-0-18'
            },
            {
              title: '正软限位开关 p2580',
              key: 'lib5-0-19'
            },
            {
              title: '负软限位开关 p2581',
              key: 'lib5-0-20'
            },
            {
              title: '绝对编码器校正位置 P2599',
              key: 'lib5-0-21'
            },
            {
              title: '自定义PZD发送字 P29151',
              key: 'lib5-0-22'
            },
          ],
        },
        {
          title: 'Speed',
          key: 'lib5-1',
          children: [
            {
              title: '速度环增益Kp V90 P29120 /S210 P1460',
              key: 'lib5-1-0',
            },
            {
              title: '速度环积分时间Tn V90 P29121 / S210 P1462',
              key: 'lib5-1-1',
            },
            {
              title: '斜坡上升时间 P1120',
              key: 'lib5-1-2',
            },
            {
              title: '斜坡下降时间 P1121',
              key: 'lib5-1-3',
            },
            {
              title: '斜坡圆弧起始时间 P1130',
              key: 'lib5-1-4',
            },
            {
              title: '斜坡圆弧结束时间 P1131',
              key: 'lib5-1-5',
            },
            {
              title: 'OFF3斜坡下降时间 P1135',
              key: 'lib5-1-6',
            },
            {
              title: '静态检测的监控时间 P1227',
              key: 'lib5-1-7',
            },
          ],
        },
      ]
    },

  ];

  const g120DeviceColumns: ProColumns[] = [
    {
      title: '序号',
      dataIndex: 'index',
      valueType: 'index',
      width: 50,
    },
    {
      title: '唯一编号',
      search: false,
      dataIndex: 'identification',
      width: 150,
      render: (text, record, _, action) => (
        <a
          key="deviceInfo"
          onClick={() => {
            setTab('tab1-2');
            setDeviceId(record.id);
            setDeviceName(record.deviceName);
            setTab2Disable(false);
            // actionRef.current?.reload();
          }}
        >
          {text}
        </a>
      ),
    },
    {
      title: '设备名称',
      dataIndex: 'deviceName',
      width: 150,
    },
    {
      title: '设备信息登记表编号',
      dataIndex: 'deviceIdentification',
      width: 150,
      search: false,
    },
    {
      title: '轴数量',
      dataIndex: 'driveNum',
      width: 110,
      search: false,
    },
    {
      title: '行业',
      dataIndex: 'vm',
      // align: 'center',
      valueType: 'select',
      width: 80,
      valueEnum: {
        1: { text: '电子' },
        2: { text: '电池' },
        3: { text: '物流' },
        4: { text: '汽车' },
        5: { text: '太阳能' },
        6: { text: '增材制造' },
        7: { text: '包装' },
        8: { text: '食品饮料' },
        9: { text: '金属加工' },
        10: { text: '其他' },
      },
      search: false,
    },
    {
      title: '负载重量',
      dataIndex: 'loadWeight',
      width: 80,
      valueEnum: {
        0: { text: '<=2T' },
        1: { text: '>2T' },
      },
      search: false,
    },
    {
      title: '备注',
      dataIndex: 'memo',
      width: 110,
      search: false,
    },
    {
      title: '创建人',
      search: false,
      dataIndex: 'createName',
      width: 80,
    },
    {
      title: '创建时间',
      search: false,
      dataIndex: 'createDate',
      width: 150,
      sorter: true,
    },
    {
      title: '创建时间', //表头显示的名称
      valueType: 'dateRange',
      hideInTable: true,
      dataIndex: 'createDate',
    },
    {
      title: '操作',
      valueType: 'option',
      key: 'option',
      fixed: 'right',
      width: 100,
      render: (text, record, _, action) => {
        const buttonList = [];
        buttonList.push(
          <a
            key="editKey"
            onClick={() => {
              setDeviceVisG120(true);
              console.log(record, "----record---");
              setDeviceG120Values(record);
            }}
          >
            编辑
          </a>,
        );
        buttonList.push(
          <a
            key="deleteKey"
            onClick={() => {
              Modal.confirm({
                title: '设备删除',
                content: '是否删除？',
                okText: '是',
                cancelText: '否',
                onOk: async () => {
                  await delG120DeviceInfo({ id: record.id });
                  tableActionRef.current?.reload();
                  message.success('删除成功！');
                },
              });
            }}
          >
            删除
          </a>,
        );
        return buttonList;
      },
    }
  ];


  useEffect(() => {
    (async () => {
    })();
  }, []);

  const onExpand = (expandedKeysValue: React.Key[]) => {
    console.log('onExpand', expandedKeysValue);
    // if not set autoExpandParent to false, if children expanded, parent can not collapse.
    // or, you can remove all expanded children keys.
    setExpandedKeys(expandedKeysValue);
    setAutoExpandParent(false);
  };

  const onCheck = (checkedKeysValue: React.Key[]) => {
    console.log('onCheck', checkedKeysValue);
    setCheckedKeys(checkedKeysValue);
  };

  const onFinish = async () => {
    try {
      const result = driveRef.current.getFieldsValue();
      console.log(result, '---result2---');
      console.log(values, "---test values---");
      if (axiosCreate) {
        result.id = (Math.random() * 1000000).toFixed(0);
        setDataSource([...dataSource, result]);
        delete result.vmaxEposTran;
        await addDriveParaCal(result);
        message.success('添加成功');
      } else {
        if (result.id !== null && result.id !== undefined) {
          for (let i = 0; i < dataSource.length; i++) {
            if (dataSource[i].id === result.id) {
              result.searchable = 1;
              console.log(result, "---result---");
              Object.assign(dataSource[i], result);
            }
          }
          // setDataSource(dataSource);
          setDataSource(dataSource);
          delete result.vmaxEposTran;
          await updateDriveParaCal(result);
          message.success('更新成功');
        }
      }
      actionRef.current.reload();
      setLibCommVis(false);
      setEditVis(false);
      setExportVis(false);
    } catch{}
  };

  const onFinishTwo = async () => {
    try {
      const result = driveRef.current.getFieldsValue();
      console.log(result, '---result2---');
      console.log(values, "---test values---");
      if (axiosCreate) {
        result.id = (Math.random() * 1000000).toFixed(0);
        setDataSourceTwo([...dataSourceTwo, result]);
        await addDriveParaCal(result);
        message.success('添加成功');
      } else {
        if (result.id !== null && result.id !== undefined) {
          for (let i = 0; i < dataSourceTwo.length; i++) {
            if (dataSourceTwo[i].id === result.id) {
              console.log(result, "---result---");
              Object.assign(dataSourceTwo[i], result);
            }
          }
          // setDataSource(dataSource);
          setDataSourceTwo(dataSourceTwo);
          await updateDriveParaCal(result);
          message.success('更新成功');
        }
      }
      actionRef.current.reload();
      setLibCommVis(false);
      setEditVis(false);
      setExportVis(false);
    } catch{}
  };

  const onG120Finish = async () => {
    try {
      const result = driveRef.current.getFieldsValue();
      console.log(result, "---result---");
      if (g120Create) {
        result.id = (Math.random() * 1000000).toFixed(0);
        setG120DataSource([...g120DataSource, result]);
        await addDriveParaCalG120({
          ...result,
          deviceInfoExtraId: deviceId,
        });
        message.success('添加成功');
      } else {
        if (result.id !== null && result.id !== undefined) {
          for (let i = 0; i < g120DataSource.length; i++) {
            if (g120DataSource[i].id === result.id) {
              Object.assign(g120DataSource[i], result);
            }
          }
          setG120DataSource(g120DataSource);
          await updateDriveParaCalG120({
            ...result,
            deviceInfoExtraId: deviceId,
          });
          message.success('更新成功');
        }
      }
      actionRef.current?.reload();
      setG120CommVis(false);
    } catch { };
  };


  return (
    <PageHeaderWrapper title={false} breadcrumb={undefined}>
      <ProCard split="vertical">
        <ProCard split="horizontal" colSpan="20%">
          <ProCard title="驱动选择" colSpan="100%" style={{ maxWidth: '100%', height: '10%' }}>
            <Radio.Group onChange={onRadioChange} value={radioValue} style={{textAlign: "center"}}>
              <Radio value={1}>V90/S210</Radio>
              <Radio value={2}>G120</Radio>
            </Radio.Group>
          </ProCard>
          <ProCard title="可选显示项" colSpan="100%" style={{ maxWidth: '100%', height: '90%' }}>
            <Tree
              checkable
              onExpand={(expandedKeysValue: React.Key[]) => {
                console.log('onExpand', expandedKeysValue);
                // if not set autoExpandParent to false, if children expanded, parent can not collapse.
                // or, you can remove all expanded children keys.
                setExpandedKeys(expandedKeysValue);
                setAutoExpandParent(false);
              }}
              expandedKeys={expandedKeys}
              autoExpandParent={autoExpandParent}
              onCheck={onCheck}
              checkedKeys={checkedKeys}
              treeData={radioValue == 1? treeData : tab == "tab1-2" || tab == "tab1-3"? G120TreeData("a") : []}
            />
          </ProCard>
        </ProCard>
        {radioValue == 1 ?
        <ProCard colSpan="80%" style={{ maxWidth: '100%', height: '100%' }} tabs={{type: 'card',}}>
          <ProCard.TabPane key="tab1" tab="计算页" destroyInactiveTabPane={true}>
            <ProList<any>
              headerTitle="驱动参数列表"
              search={{}}
              actionRef={actionRef}
              rowKey="id"
              rowSelection={rowSelection}
              expandable={{ expandedRowKeys, onExpandedRowsChange: setExpandedRowKeys }}
              dataSource={dataSourceTwo}
              toolBarRender={(action, { selectedRows, selectedRowKeys }) => [
                <Button
                  key="button"
                  icon={<CloudUploadOutlined />}
                  type="primary"
                  onClick={() => {
                    setUploadVis(true);
                  }}
                >
                  导入
                </Button>,
                <Button
                  key="button"
                  icon={<PlusOutlined />}
                  type="primary"
                  onClick={() => {
                    setLibCommVis(true);
                    setAxiosCreate(true);
                  }}
                >
                  新建
                </Button>,
                <Button
                  key="button"
                  icon={<CarryOutOutlined />}
                  onClick={() => {
                    Modal.confirm({
                      title: '匹配',
                      content: '是否进行匹配',
                      okText: '是',
                      cancelText: '否',
                      onOk: async () => {
                        await matchDriveParasCal(selectedRowKeys);
                        actionRef.current?.reload();
                        message.success('匹配成功！');
                      },
                    });
                  }}
      
                  type="dashed"
                >
                  匹配
                </Button>,
                <Button
                  key="button"
                  icon={<CalculatorOutlined />}
                  onClick={() => {
                    Modal.confirm({
                      title: '计算',
                      content: '是否计算？',
                      okText: '是',
                      cancelText: '否',
                      onOk: async () => {
                        await calDriveParasCal(selectedRowKeys);
                        actionRef.current?.reload();
                        message.success('计算成功！');
                      },
                    });
                  }}
                  type="dashed"
                >
                  计算
                </Button>,
                <Button
                  key="button"
                  icon={<CloudDownloadOutlined />}
                  onClick={() => {
                    let tempRefSpeed = null;
                    for (let i = 0; i < dataSourceTwo.length; i++) {
                      if (dataSourceTwo[i].id === selectedRowKeys[0]) {
                        tempRefSpeed = dataSourceTwo[i].refSpeed;
                      }
                    }
                    if (tempRefSpeed !== null) {
                      setExportVis(true);
                    } else {
                      message.error('请先计算后再导出！');
                    } 
                  }}

                  type="link"
                >
                  导出
                </Button>,
                <Button
                  key="button"
                  icon={<CloudDownloadOutlined />}
                  shape='round'
                  onClick={() => {
                    let tempRefSpeed = null;
                    for (let i = 0; i < dataSourceTwo.length; i++) {
                      if (dataSourceTwo[i].id === selectedRowKeys[0]) {
                        tempRefSpeed = dataSourceTwo[i].refSpeed;
                      }
                    }
                    if (tempRefSpeed !== null) {
                      setExportPMVis(true);
                    } else {
                      message.error('请先计算后再导出！');
                    } 
                  }}

                  type="primary"
                >
                  包装机版导出
                </Button>,
                <Button
                  key="button"
                  icon={<DeleteOutlined />}
                  onClick={() => {
                    Modal.confirm({
                      title: '批量删除',
                      content: '是否删除？',
                      okText: '是',
                      cancelText: '否',
                      onOk: async () => {
                        await delDriveParasCal(selectedRowKeys);
                        actionRef.current?.reload();
                        message.success('删除成功！');
                      },
                    });
                  }}

                  type="default"
                >
                  批量删除
                </Button>,             
              ]}
              metas={{
                title: {
                  dataIndex: 'index',
                  valueType: 'index',
                  search: false,
                },

                subTitle: {
                  search: false,
                  render: (text, row) => {
                    return (
                      <DriveParaSubtitle
                        row={row}
                        checkedKeys={checkedKeys}
                      />
                    )
                  }
                },

                description: {
                  dataIndex: 'para',
                  search: false,
                  render: (_, row) => {
                    return (
                      <DriveParaDescription
                        isCalc={true}
                        row={row}
                      />
                    );
                  }
                },

                content: {
                  search: false,
                },
                actions:{
                  search: false,
                  render: (text, row) => [
                    <a
                      href={row.html_url}
                      target="_blank"
                      rel="noopener noreferrer"
                      key="modify"
                      onClick={async () => {
                        setAxiosCreate(false);
                        setEditVis(true);
                        if (row.vmaxEpos == null && row.vmaxEpos == undefined) {
                          setValues({...row});
                        } else if (row.positionAccuracy == null && row.positionAccuracy == undefined) {
                          setValues({...row});
                        } else {
                          setValues({ ...row, vmaxEposTran: 6 * row.vmaxEpos * row.positionAccuracy });
                        } 
                        }}
                    >
                      编辑
                    </a>,
                    <a
                      href={row.html_url}
                      target="_blank"
                      rel="noopener noreferrer"
                      key="copy"
                      onClick={async () => {
                        let addone = {};
                        dataSourceTwo
                          .filter((item) => item.id == row.id)
                          .map((item) => {
                            addone = { ...item };
                          });
                        addone.id = (Math.random() * 1000000).toFixed(0);  
                        setDataSourceTwo([...dataSourceTwo, addone]);
                        delete addone.identification;
                        await addDriveParaCal(addone);
                        actionRef.current.reload();
                      }}
                    >
                      复制
                    </a>,
                    <a
                      href={row.html_url}
                      target="_blank"
                      rel="noopener noreferrer"
                      key="delete"
                      onClick={async () => {
                        setDataSourceTwo(dataSourceTwo.filter((item) => item.id !== row.id));
                        delete row.identification;
                        await delDriveParaCal(row);
                        actionRef.current.reload();
                      }}
                    >
                      删除
                    </a>,
                  ],
                },

                motorOrderNum: {
                  title: '电机订货号'
                },
                
              }}
              request={async (params = {}, sort, filter) => {
                console.log(params, sort, filter);
                const result = await getDriveParaCalByPage({
                  ...params,
                  searchable: null,
                  });
                console.log(result, "---result---");
                setDataSourceTwo(result.data.content);
                return {
                  data: result.data.content,
                  total: result.data.totalElements,
                  success: result.success,
                };
              }}
              pagination={{
                showSizeChanger: true,
              }}
              />
          
            <DriveParaCalcCommon
              visible={libCommVis}
              title="驱动参数计算新建"
              disable={false}
              values={values}
              ref={driveRef}
              initialValues={values}
              isDriveParaCalc={true}
              onCancel={() => {
                setLibCommVis(false);
              }}
              onOk={onFinishTwo}
            />

            <UploadFileSave
              visible={uploadVis}
              tableHeader={columns}
              errorStatus={false}
              ref={uploadRef}
              onOk={async (tables, tableHeader) => {
                console.log(tables, "---tables---");
                
                console.log(uploadRef.current.fileList, '文件测试---');
                // formData.append('file', uploadRef.current.fileList);
                // console.log(formData, "---formData---");
                // uploadRef.current.fileList.map((file) => {
                //   formData.append('file', file);
                // });
                const result = await uploadDriveParaCalExcel(formData);
                
                console.log(result, "---formData---");
                if (result != undefined && result != null) {
                  setDataSourceTwo([...dataSourceTwo, result.data]);
                }
                // setDataSourceTwo(tables);
                actionRef.current?.reload();
                setUploadVis(false);
              }}
              onChange={(file) => {
                formData.append('file', file);
                console.log(file, "---file---");
              }}
              onCheck={() => {}}
              onCancel={() => {
                setUploadVis(false);
              }}
              title="驱动参数库上传预览"
            />

            <DriveParaCalcEdit
              visible={editVis}
              title="驱动参数计算编辑"
              disable={false}
              values={values}
              ref={driveRef}
              initialValues={values}
              onCancel={() => {
                setEditVis(false);
              }}
              onOk={onFinishTwo}
            />

            <ModalForm
              title="导出"
              visible={exportVis}
              formRef={exportFormRef}
              onFinish={async(temp) =>{
                console.log(selectedRowKeys, "---selectRows---");
                const result = afterExportUpdate({
                  paraIds: selectedRowKeys,
                  searchable: temp.searchable,
                  original: temp.original,
                  deviceInfoId: temp.deviceInfoId,
                });
                
                console.log(result, "---values2---");

                driveParaCalExcelExport(selectedRowKeys).then((res) => {
                  const aLink = document.createElement('a');
                  document.body.appendChild(aLink);
                  aLink.style.display = 'none';
                  // aLink.href = window.URL.createObjectURL(res);
                  let binaryData = [];
                  binaryData.push(res);
                  aLink.href = window.URL.createObjectURL(new Blob(binaryData));
                  aLink.setAttribute('download', `驱动参数计算${new Date()}.xlsx`);
                  aLink.click();
                  document.body.removeChild(aLink);
                });
                  
                // await updateDriveParaCal(values);
                message.success('更新成功');
                actionRef.current?.reload();
                setExportVis(false);
            
              }}
              onValuesChange={(changeValues) => {
                if (changeValues.original != null && changeValues.original != undefined) {
                  if (changeValues.original === 1) {
                    setDeviceDisabled(true);
                    exportFormRef.current?.setFieldsValue({
                      deviceInfoId: null
                    });
                  } else {
                    setDeviceDisabled(false);
                  }
                }
              }}
              modalProps={{
                destroyOnClose: true,
                onCancel: () => {setExportVis(false)},
              }}
              layout={formLayoutType}
              grid={grid}
              rowProps={{
                gutter: [12, formLayoutType === 'inline' ? 12 : 0],
              }}
            >
              <ProFormGroup key="common1" title="是否存储">
                <ProFormSelect
                  width="md"
                  name="searchable"
                  label="是否存入数据库"
                  options={[
                    { label: '是', value: 1 },
                    { label: '否', value: 0 },
                  ]}
                  colProps={{ md: 12, xl: 8 }}
                  rules={[{ required: true, message: '此项是必填项目' }]}
                />
              </ProFormGroup>

              <ProFormDependency name={['searchable']}>
                {({ searchable }) => {
                  if (searchable === 1) {
                    return [
                      <ProFormGroup key="common2" title="存储详情">
                        <ProFormSelect
                          width="md"
                          name="original"
                          label="来源"
                          options={[
                            { label: '来自设备信息管理', value: 0 },
                            { label: '其他', value: 1 },
                          ]}
                          colProps={{ md: 12, xl: 8 }}
                          // rules={[{ required: true, message: '此项是必填项目' }]}
                        />
                        <ProFormSelect
                          showSearch
                          width="md"
                          name="deviceInfoId"
                          label="设备信息"
                          // rules={[{ required: true, message: '必须选取设备' }]}
                          colProps={{ md: 12, xl: 12 }}
                          debounceTime={1000}
                          disabled={deviceDisabled}
                          request={async (params) => {
                            console.log(params, '--params-');
                            const result = await calcDeviceList({ blurry: params.keyWords });
                            return result.data.map((item) => {
                              return {
                                key: item.id,
                                label: item.identification,
                                value: item.id,
                              };
                            });
                          }}
                          fieldProps={{
                            onChange: () => {
                              exportFormRef.current?.setFieldsValue({
                                searchable: 1,
                              });
                              }
                          }}
                        />
                      </ProFormGroup>
                    ];
                  } else {
                    return;
                  }
                }}
              </ProFormDependency>
            </ModalForm>
            
            <ModalForm
              title="包装机版导出"
              visible={exportPMVis}
              formRef={exportFormRef}
              onFinish={async(temp) =>{
                console.log(selectedRowKeys, "---selectRows---");
                const result = afterExportUpdate({
                  paraIds: selectedRowKeys,
                  searchable: temp.searchable,
                  original: temp.original,
                  deviceInfoId: temp.deviceInfoId,
                });
                
                console.log(result, "---values2---");

                driveParaCalExcelExportPMVer(selectedRowKeys).then((res) => {
                  const aLink = document.createElement('a');
                  document.body.appendChild(aLink);
                  aLink.style.display = 'none';
                  // aLink.href = window.URL.createObjectURL(res);
                  let binaryData = [];
                  binaryData.push(res);
                  aLink.href = window.URL.createObjectURL(new Blob(binaryData));
                  aLink.setAttribute('download', `包装机版驱动参数计算${new Date()}.xlsx`);
                  aLink.click();
                  document.body.removeChild(aLink);
                });
                  
                // await updateDriveParaCal(values);
                message.success('更新成功');
                actionRef.current?.reload();
                setExportPMVis(false);
            
              }}
              onValuesChange={(changeValues) => {
                if (changeValues.original != null && changeValues.original != undefined) {
                  if (changeValues.original === 1) {
                    setDeviceDisabled(true);
                    exportFormRef.current?.setFieldsValue({
                      deviceInfoId: null
                    });
                  } else {
                    setDeviceDisabled(false);
                  }
                }
              }}
              modalProps={{
                destroyOnClose: true,
                onCancel: () => {setExportPMVis(false)},
              }}
              layout={formLayoutType}
              grid={grid}
              rowProps={{
                gutter: [12, formLayoutType === 'inline' ? 12 : 0],
              }}
            >
              <ProFormGroup key="common1" title="是否存储">
                <ProFormSelect
                  width="md"
                  name="searchable"
                  label="是否存入数据库"
                  options={[
                    { label: '是', value: 1 },
                    { label: '否', value: 0 },
                  ]}
                  colProps={{ md: 12, xl: 8 }}
                  rules={[{ required: true, message: '此项是必填项目' }]}
                />
              </ProFormGroup>

              <ProFormDependency name={['searchable']}>
                {({ searchable }) => {
                  if (searchable === 1) {
                    return [
                      <ProFormGroup key="common2" title="存储详情">
                        <ProFormSelect
                          width="md"
                          name="original"
                          label="来源"
                          options={[
                            { label: '来自设备信息管理', value: 0 },
                            { label: '其他', value: 1 },
                          ]}
                          colProps={{ md: 12, xl: 8 }}
                          // rules={[{ required: true, message: '此项是必填项目' }]}
                        />
                        <ProFormSelect
                          showSearch
                          width="md"
                          name="deviceInfoId"
                          label="设备信息"
                          // rules={[{ required: true, message: '必须选取设备' }]}
                          colProps={{ md: 12, xl: 12 }}
                          debounceTime={1000}
                          disabled={deviceDisabled}
                          request={async (params) => {
                            console.log(params, '--params-');
                            const result = await calcDeviceList({ blurry: params.keyWords });
                            return result.data.map((item) => {
                              return {
                                key: item.id,
                                label: item.identification,
                                value: item.id,
                              };
                            });
                          }}
                          fieldProps={{
                            onChange: () => {
                              exportFormRef.current?.setFieldsValue({
                                searchable: 1,
                              });
                              }
                          }}
                        />
                      </ProFormGroup>
                    ];
                  } else {
                    return;
                  }
                }}
              </ProFormDependency>
            </ModalForm>

          </ProCard.TabPane> 
          <ProCard.TabPane key="tab2" tab="查找页">
            <ProList<any>
              headerTitle="驱动参数列表"
              search={{}}
              actionRef={actionRef}
              rowKey="id"
              rowSelection={rowSelection}
              expandable={{ expandedRowKeys, onExpandedRowsChange: setExpandedRowKeys }}
              dataSource={dataSource}
                toolBarRender={(action, { selectedRows, selectedRowKeys }) => [
                  <Button
                  key="button"
                  icon={<CloudDownloadOutlined />}
                  onClick={() => {
                    let tempRefSpeed = null;
                    for (let i = 0; i < dataSourceTwo.length; i++) {
                      if (dataSourceTwo[i].id === selectedRowKeys[0]) {
                        tempRefSpeed = dataSourceTwo[i].refSpeed;
                      }
                    }
                    driveParaCalExcelExport(selectedRowKeys).then((res) => {
                      const aLink = document.createElement('a');
                      document.body.appendChild(aLink);
                      aLink.style.display = 'none';
                      // aLink.href = window.URL.createObjectURL(res);
                      let binaryData = [];
                      binaryData.push(res);
                      aLink.href = window.URL.createObjectURL(new Blob(binaryData));
                      aLink.setAttribute('download', `驱动参数计算${new Date()}.xlsx`);
                      aLink.click();
                      document.body.removeChild(aLink);
                    });
                      
                    // await updateDriveParaCal(values);
                    message.success('导出成功');
                    actionRef.current?.reload();    
                    // if (tempRefSpeed !== null) {
                    //   setExportVis(true);
                    // } else {
                    //   message.error('请先计算后再导出！');
                    // } 
                  }}

                  type="link"
                >
                  导出
                  </Button>,
                  <Button
                  key="button"
                    icon={<CloudDownloadOutlined />}
                    shape='round'
                  onClick={() => {
                    let tempRefSpeed = null;
                    for (let i = 0; i < dataSourceTwo.length; i++) {
                      if (dataSourceTwo[i].id === selectedRowKeys[0]) {
                        tempRefSpeed = dataSourceTwo[i].refSpeed;
                      }
                    }
                    driveParaCalExcelExportPMVer(selectedRowKeys).then((res) => {
                      const aLink = document.createElement('a');
                      document.body.appendChild(aLink);
                      aLink.style.display = 'none';
                      // aLink.href = window.URL.createObjectURL(res);
                      let binaryData = [];
                      binaryData.push(res);
                      aLink.href = window.URL.createObjectURL(new Blob(binaryData));
                      aLink.setAttribute('download', `驱动参数计算${new Date()}.xlsx`);
                      aLink.click();
                      document.body.removeChild(aLink);
                    });
                      
                    // await updateDriveParaCal(values);
                    message.success('导出成功');
                    actionRef.current?.reload();    
                  }}

                  type="primary"
                >
                  包装机版导出
                </Button>,
                <Button
                  key="button"
                  icon={<DeleteOutlined />}
                  onClick={() => {
                    Modal.confirm({
                      title: '批量删除',
                      content: '是否删除？',
                      okText: '是',
                      cancelText: '否',
                      onOk: async () => {
                        await delDriveParasCal(selectedRowKeys);
                        actionRef.current?.reload();
                        message.success('删除成功！');
                      },
                    });
                  }}

                  type="default"
                >
                  批量删除
                </Button>, 
              ]}
              metas={{
                title: {
                  dataIndex: 'index',
                  valueType: 'index',
                  search: false,
                },

                subTitle: {
                  search: false,
                  render: (text, row) => {
                    return (
                      <DriveParaSubtitle row={row} checkedKeys={checkedKeys}/>
                    )
                  }
                },

                description: {
                  dataIndex: 'para',
                  search: false,
                  render: (_, row) => {
                    return (
                      <DriveParaDescription isCalc={true} row={row}/>
                    );
                  }
                },

                content: {
                  search: false,
                },
                actions:{
                  search: false,
                  render: (text, row) => [
                    <a
                      href={row.html_url}
                      target="_blank"
                      rel="noopener noreferrer"
                      key="modify"
                      onClick={async () => {
                        setAxiosCreate(false);
                        setEditVis(true);
                        if (row.vmaxEpos == null && row.vmaxEpos == undefined) {
                          setValues({...row});
                        } else if (row.positionAccuracy == null && row.positionAccuracy == undefined) {
                          setValues({...row});
                        } else {
                          setValues({ ...row, vmaxEposTran: 6 * row.vmaxEpos * row.positionAccuracy });
                        } 
                        }}
                    >
                      编辑
                    </a>,
                    <a
                      href={row.html_url}
                      target="_blank"
                      rel="noopener noreferrer"
                      key="copy"
                      onClick={async () => {
                        let addone = {};
                        dataSource
                          .filter((item) => item.id == row.id)
                          .map((item) => {
                            addone = { ...item };
                          });
                        addone.id = (Math.random() * 1000000).toFixed(0);  
                        setDataSource([...dataSource, addone]);
                        delete addone.identification;
                        await addDriveParaCal(addone);
                        actionRef.current.reload();
                      }}
                    >
                      复制
                    </a>,
                    <a
                      href={row.html_url}
                      target="_blank"
                      rel="noopener noreferrer"
                      key="delete"
                      onClick={async () => {
                        setDataSource(dataSource.filter((item) => item.id !== row.id));
                        delete row.identification;
                        await delDriveParaCal(row);
                        actionRef.current.reload();
                      }}
                    >
                      删除
                    </a>,
                  ],
                },

                motorOrderNum: {
                  title: '电机订货号'
                },
                
              }}
              request={async (params = {}, sort, filter) => {
                console.log(params, sort, filter);
                const result = await getDriveParaCalByPage({...params, searchable: 1});
                console.log(result, "---result---");
                setDataSource(result.data.content);
                return {
                  data: result.data.content,
                  total: result.data.totalElements,
                  success: result.success,
                };
              }}
              pagination={{
                showSizeChanger: true,
              }}
            />
            <DriveParaCalcEdit
              visible={editVis}
              title="驱动参数计算编辑"
              disable={false}
              values={values}
              ref={driveRef}
              initialValues={values}
              onCancel={() => {
                setEditVis(false);
              }}
              onOk={onFinish}
            />
          </ProCard.TabPane>
        </ProCard> :
        <ProCard
          colSpan="80%"
          style={{ maxWidth: '100%', height: '100%' }}
          layout='center'
          tabs={{
            type: 'card',
            tabPosition,
            activeKey: tab,
            destroyInactiveTabPane: true,
            items: [
              {
                label: '设备管理',
                key: 'tab1-1',
                children: [
                  <ProTable
                    headerTitle="设备列表"
                    actionRef={tableActionRef}
                    formRef={tableRef}
                    rowKey="id"
                    columns={g120DeviceColumns}
                    toolBarRender={(action, { selectedRows, selectedRowKeys }) => { 
                      return [
                        <Button
                          key="button"
                          icon={<PlusOutlined />}
                          type="primary"
                          onClick={async () => {
                            await addG120DeviceInfo({
                              // id: (Math.random() * 1000000).toFixed(0),
                              deviceName: 'Temp_Device_1',
                              driveNum: 0,
                              calcDeviceG120: 1,
                              loadWeight: 0,
                            });
                            message.success("新建设备成功");
                            tableActionRef.current?.reload();
                          }}
                        >
                          新建设备
                        </Button>
                      ];
                    }}
                    revalidateOnFocus={false}
                    request={async (params = {}, sort, filter) => { 
                      let result;
                      result = await getDeviceInfoLibByPage({
                        ...params,
                        calcDeviceG120: 1,
                      });
                      return {
                        data: result.data.content,
                        total: result.data.totalElements,
                        success: result.success,
                      };    
                    }}
                    onDataSourceChange={(value) => {
                      // 如果实在要保存新的值就需要在这边进行处理
                      // console.log(value, selectedRowKeys, '---teee');
                    }}
                    rowSelection={rowSelection}
                    pagination={{
                      showSizeChanger: true,
                    }}
                    scroll={{ x: 1070, y: 350 }}
                  />,
                  <ModalForm
                    title="选择设备"
                    visible={deviceVisG120}
                    initialValues={deviceG120Values}
                    formRef={formRef}
                    onFinish={async (temp) => {
                      await updateG120DeviceInfo({
                        ...temp,
                        id: deviceG120Values.id,
                        identification: deviceG120Values.identification,
                        driveNum: deviceG120Values.driveNum,
                        calcDeviceG120: 1,
                      });
                      setDeviceVisG120(false);
                      tableActionRef.current?.reload();
                    }}
                    // onValuesChange={ }
                    modalProps={{
                      destroyOnClose: true,
                      onCancel: () => { setDeviceVisG120(false) },
                    }}
                    layout='horizontal'
                    grid={grid}
                    rowProps={{
                      gutter: [12, 0],
                    }}
                  >
                    <ProFormGroup key="common1-2">
                      <ProFormText
                        width="md"
                        name="deviceName"
                        label="设备名称"
                        colProps={{ md: 14, xl: 10 }}
                        rules={[{ required: true, message: '请输入设备名称信息' }]}
                      />
                      <ProFormSelect
                        fieldProps={{
                          //这里使用了select的onChange方法，必须使用这样的写法来进行调用onChange方法
                          onChange: (val, val2) => {
                            console.log(val, val2);
                          },
                        }}
                        colProps={{ md: 12, xl: 6 }}
                        // initialValue={1}
                        name="vm"
                        label="行业"
                        options={[
                          { label: '电子', value: 1 },
                          { label: '电池', value: 2 },
                          { label: '物流', value: 3 },
                          { label: '汽车', value: 4 },
                          { label: '太阳能', value: 5 },
                          { label: '增材制造', value: 6 },
                          { label: '包装', value: 7 },
                          { label: '食品饮料', value: 8 },
                          { label: '金属加工', value: 9 },
                          { label: '其他', value: 10 },
                        ]}
                      />
                      <ProFormSelect
                        fieldProps={{
                          onChange: (val, val2) => {
                            console.log(val, val2);
                          },
                        }}
                        colProps={{ md: 12, xl: 6 }}
                        name="loadWeight"
                        label="负载重量"
                        options={[
                          { label: '<=2T', value: 0 },
                          { label: '>2T', value: 1 },
                        ]}
                      />
                      <ProFormTextArea
                        colProps={{ span: 22 }}
                        name="memo"
                        label="备注"
                      />
                    </ProFormGroup>
                    <ProFormGroup key="common1-1" style={{ marginTop: '10px' }}>
                      <ProFormSelect
                        width="md"
                        name="isFromCusDevice"
                        label="是否来自客户设备信息"
                        options={[
                          { label: '是', value: 1 },
                          { label: '否', value: 0 },
                        ]}
                        colProps={{ md: 14, xl: 10 }}
                        rules={[{ required: true, message: '此项是必填项目' }]}
                      />
                    
      
                      <ProFormDependency name={['isFromCusDevice']}>
                        {({ isFromCusDevice }) => {
                          if (isFromCusDevice === 1) {
                            return [
                              <ProFormSelect
                                showSearch
                                width="md"
                                name="cusDeviceId"
                                label="设备信息"
                                // rules={[{ required: true, message: '必须选取设备' }]}
                                colProps={{ md: 12, xl: 12 }}
                                debounceTime={1000}
                                request={async (params) => {
                                  console.log(params, '--params-');
                                  const result = await calcDeviceList({ blurry: params.keyWords });
                                  return result.data.map((item) => {
                                    return {
                                      key: item.id,
                                      label: item.identification,
                                      value: item.id,
                                    };
                                  });
                                }}
                                fieldProps={{
                                  onChange: () => {
                                    formRef.current?.setFieldsValue({
                                      isFromCusDevice: 1,
                                    });
                                    }
                                }}
                              />
                            ];
                          } else {}
                        }}
                      </ProFormDependency>
                    </ProFormGroup>
                  </ModalForm>,
                ]
              },
              {
                label: '轴信息管理',
                key: 'tab1-2',
                disabled: tab2Disable,
                children: [
                  <ProList<any>
                    headerTitle="G120驱动参数列表"
                    search={{}}
                    actionRef={actionRef}
                    rowKey="id"
                    rowSelection={rowSelection}
                    expandable={{ expandedRowKeys, onExpandedRowsChange: setExpandedRowKeys }}
                    toolBarRender={() => [
                      <Button
                        key="button"
                        icon={<PlusOutlined />}
                        type="primary"
                        onClick={() => {
                          setG120CommVis(true);
                          setG120Create(true);
                          setG120Values({});
                        }}
                      >
                        新建轴
                      </Button>,
                      <Button
                        key="button"
                        icon={<PlusOutlined />}
                        type="primary"
                        onClick={() => {
                          setUploadVisG120(true);
                        }}
                      >
                        导入
                      </Button>,
                      <Button
                        key="button"
                        icon={<CarryOutOutlined />}
                        type="dashed"
                        onClick={() => {
                          Modal.confirm({
                            title: '匹配',
                            content: '是否进行匹配',
                            okText: '是',
                            cancelText: '否',
                            onOk: async () => {
                              // await matchDriveParasCal(selectedRowKeys);
                              // actionRef.current?.reload();
                              message.success('匹配成功！');
                            },
                          });
                        }}
                      >
                        匹配
                      </Button>,
                        <Button
                        key="button"
                        icon={<CalculatorOutlined />}
                        type="dashed"
                          onClick={async () => {
                            // setG120DataSource([...g120DataSource, deviceId]);
                            console.log(g120DataSource, "---g120DataSource---");
                            await calDriveParasCalG120(g120DataSource);
                            message.success('计算成功！');
                            actionRef.current.reload();
                        }}
                      >
                        计算
                      </Button>,
                      <Button
                        key="button"
                        icon={<CloudDownloadOutlined />}
                        onClick={async () => {
                          await driveParaCalG120ExcelExport(g120DataSource).then((res) => {
                            const aLink = document.createElement('a');
                            document.body.appendChild(aLink);
                            aLink.style.display = 'none';
                            // aLink.href = window.URL.createObjectURL(res);
                            let binaryData = [];
                            binaryData.push(res);
                            aLink.href = window.URL.createObjectURL(new Blob(binaryData));
                            aLink.setAttribute('download', `${deviceName} G120驱动参数计算${new Date()}.xlsx`);
                            aLink.click();
                            document.body.removeChild(aLink);
                          });
                          message.success('导出成功');
                          actionRef.current.reload();
                        }}
                        type="link"
                      >
                        导出
                      </Button>,
                      <Button
                        key="button"
                        icon={<DeleteOutlined />}
                        type="primary"
                        onClick={() => {
                          Modal.confirm({
                            title: '批量删除',
                            content: '是否删除？',
                            okText: '是',
                            cancelText: '否',
                            onOk: async () => {
                              await delDriveParasCalG120(selectedRowKeys);
                              actionRef.current?.reload();
                              message.success('删除成功！');
                            },
                          });
                        }}
                      >
                        批量删除
                      </Button>,
                    ]}
                    metas={{
                      title: {
                        dataIndex: 'index',
                        valueType: 'index',
                        search: false,
                      },
      
                      subTitle: {
                        search: false,
                        render: (text, row) => {
                          return (
                            <G120DriveParaSubtitle
                              row={row}
                              checkedKeys={checkedKeys}
                            />
                          );
                        }
                      },
      
                      description: {
                        dataIndex: 'para',
                        search: false,
                        render: (_, row) => {
                          return (
                            <>
                              {/* <Tag>{'电机订货号' + row.g120Motor.motorOrderNum}</Tag> */}
                            </>
                          );
                        }
                      },
      
                      content: {
                        search: false,
                      },
                      actions:{
                        search: false,
                        render: (text, row) => [
                          <a
                            href={row.html_url}
                            target="_blank"
                            rel="noopener noreferrer"
                            key="modify"
                            onClick={async () => {
                              setG120Create(false);
                              setG120CommVis(true);
                              console.log(row, '---initialValues---');
                              setG120Values({ ...row });
                            }}
                          >
                            编辑
                          </a>,
                          <a
                            href={row.html_url}
                            target="_blank"
                            rel="noopener noreferrer"
                            key="copy"
                            onClick={async () => {
                              let addone = {};
                              console.log(g120DataSource, "---g120DataSource---");
                              g120DataSource
                                .filter((item) => item.id == row.id)
                                .map((item) => {
                                  addone = { ...item };
                                });
                              addone.id = (Math.random() * 1000000).toFixed(0);  
                              setG120DataSource([...g120DataSource, addone]);
                              await addDriveParaCalG120({
                                ...addone,
                                deviceInfoExtraId: deviceId,
                              });
                              actionRef.current.reload();
                            }}
                          >
                            复制
                          </a>,
                          <a
                            href={row.html_url}
                            target="_blank"
                            rel="noopener noreferrer"
                            key="delete"
                            onClick={async () => {
                              setG120DataSource(g120DataSource.filter((item) => item.id !== row.id));
                              await delDriveParaCalG120({
                                ...row,
                              });
                              actionRef.current.reload();
                            }}
                          >
                            删除
                          </a>,
                        ],
                      },
      
                      shaftName: {
                        title: '轴名称',
                      },
                    }}
                    request={async (params = {}, sort, filter) => {
                      const result = await getDriveParaCalG120ByPage({
                        ...params,
                        // deviceInfoId: null,
                        deviceInfoExtraId: deviceId,
                      });
                      console.log(result, "---result---");
                      setG120DataSource(result.data.content);
                      return {
                        data: result.data.content,
                        total: result.data.totalElements,
                        success: result.success,
                      };
                    }}
                    pagination={{
                      showSizeChanger: true,
                    }}
                  />,
      
                  <G120LibEngShaftCommon
                    visible={g120CommVis}
                    title='G120工程师驱动参数库新建'
                    disabled={false}
                    values={g120Values}
                    initialValues={g120Values}
                    ref={driveRef}
                    onOk={ onG120Finish }
                    onCancel={() => {
                      setG120CommVis(false);
                    }}
                    isG120Calc={true}
                  />,
      
                  <UploadFileSave
                    visible={uploadVisG120}
                    tableHeader={G120CalcUploadColumns("a")}
                    errorStatus={false}
                    ref={uploadRef}
                    onOk={async (tables, tableHeader) => {
                      if (deviceId !== null) {
                        formData.append('deviceInfoExtraId', deviceId);
                      }
                      await uploadDriveParasCalG120Excel(formData);
                      console.log(formData, "---formData---");
                      // setDataSource([...dataSource, tables]);
                      actionRef.current.reload();
                      setUploadVisG120(false);
                    }}
                    onChange={(file) => {
                      formData.append('file', file);
                      console.log(file, "---file---");
                    }}
                    onCheck={() => {}}
                    onCancel={() => {
                      setUploadVisG120(false);
                    }}
                    title="G120工程师驱动参数库上传预览"
                  />,
                ],
              },
              {
                label: '轴信息总览',
                key: 'tab1-3',
                children: [
                  <ProList<any>
                    headerTitle="G120驱动参数列表"
                    search={{}}
                    actionRef={actionRef}
                    rowKey="id"
                    rowSelection={rowSelection}
                    expandable={{ expandedRowKeys, onExpandedRowsChange: setExpandedRowKeys }}
                    metas={{
                      title: {
                        dataIndex: 'index',
                        valueType: 'index',
                        search: false,
                      },
      
                      subTitle: {
                        search: false,
                        render: (text, row) => {
                          return (
                            <G120DriveParaSubtitle
                              row={row}
                              checkedKeys={checkedKeys}
                            />
                          );
                        }
                      },
      
                      description: {
                        dataIndex: 'para',
                        search: false,
                        render: (_, row) => {
                          return (
                            <>
                              {/* <Tag>{'电机订货号' + row.g120Motor.motorOrderNum}</Tag> */}
                            </>
                          );
                        }
                      },
      
                      content: {
                        search: false,
                      },
                      actions:{
                        search: false,
                        render: (text, row) => [
                          <a
                            href={row.html_url}
                            target="_blank"
                            rel="noopener noreferrer"
                            key="modify"
                            onClick={async () => {
                              setG120Create(false);
                              setG120CommVis(true);
                              console.log(row, '---initialValues---');
                              setG120Values({ ...row });
                            }}
                          >
                            编辑
                          </a>,
                          <a
                            href={row.html_url}
                            target="_blank"
                            rel="noopener noreferrer"
                            key="copy"
                            onClick={async () => {
                              let addone = {};
                              console.log(g120DataSource, "---g120DataSource---");
                              g120DataSource
                                .filter((item) => item.id == row.id)
                                .map((item) => {
                                  addone = { ...item };
                                });
                              addone.id = (Math.random() * 1000000).toFixed(0);  
                              setG120DataSource([...g120DataSource, addone]);
                              await addDriveParaCalG120({
                                ...addone,
                                deviceInfoExtraId: deviceId,
                              });
                              actionRef.current.reload();
                            }}
                          >
                            复制
                          </a>,
                          <a
                            href={row.html_url}
                            target="_blank"
                            rel="noopener noreferrer"
                            key="delete"
                            onClick={async () => {
                              setG120DataSource(g120DataSource.filter((item) => item.id !== row.id));
                              await delDriveParaCalG120(row);
                              actionRef.current.reload();
                            }}
                          >
                            删除
                          </a>,
                        ],
                      },

                      deviceExtraName: {
                        title: '设备名称',
                      },
                      shaftName: {
                        title: '轴名称',
                      },
                      createDate: {
                        title: '创建时间',
                        valueType: 'dateRange',
                      },
                      // deviceIdentification: {
                      //   title: '客户设备编号',
                      // },
                      // deviceExtraName: {
                      //   title: '非客户设备名称',
                      // },
      
                    }}
                    request={async (params = {}, sort, filter) => {
                      console.log(params, sort, filter);
                      console.log(deviceId, "---deviceId---");
                      const result = await getDriveParaCalG120ByPage({
                        ...params,
                      });
                      // setDeviceId(null);
                      console.log(result, "---result---");
                      setG120DataSource(result.data.content);
                      return {
                        data: result.data.content,
                        total: result.data.totalElements,
                        success: result.success,
                      };
                    }}
                    pagination={{
                      showSizeChanger: true,
                    }}
                  />,
                ],
              },
            ],
            onChange: (key) => {
              // actionRef.current?.reload();
              setTab(key);
              setTab2Disable(true);
            }
          }}
        >
            
        </ProCard>
        }
      </ProCard>
    </PageHeaderWrapper>
  );
};

export default DriveParaCalc;